from django.http import HttpResponse, JsonResponse
from django.shortcuts import render_to_response, render

from .models import User, Role, Order


def index(request):
    return render_to_response('index.html')


def query(request):
    users = User.objects.all()
    for user in users:
        print(user)

    roles = Role.objects.all()
    for role in roles:
        print(role)

    orders = Order.objects.all()
    for order in orders:
        print(order)

    return HttpResponse('query')


def add(request, x, y):
    return JsonResponse({
        'ret': x + y
    })


def page_not_found(request, exception):
    return render(request, 'error/404.html', status=404)


def server_error(request, template_name='error/500.html'):
    return render(request, template_name)


def permission_denied(request, template_name='error/403.html'):
    return render(request, template_name)
